home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / opalvisn / obrotold.lzh / Renderer.c < prev   
Encoding:
C/C++ Source or Header  |  1993-02-19  |  3.7 KB  |  189 lines

  1. #include <proto/all.h>
  2. #include <opal/opallib.h>
  3. #include <graphics/gfxbase.h>
  4. #include <exec/memory.h>
  5.  
  6.  
  7. /* Typical interface to OpalVision from a rendering package
  8.  */
  9.  
  10.  
  11. /* Define this flag if you want to open a Virtual screen if
  12.  * chip ram is running low.
  13.  */
  14.  
  15. #define OPENVIRTUAL    1
  16.  
  17. /* Define this flag if you cannot set the LSB of bit of
  18.  * the background colour.
  19.  */
  20.  
  21. /* #define AUTOSYNC    1 */
  22.  
  23.     /* external functions */
  24.  
  25. BOOL Open_OpalScreen (ULONG Modes);
  26. void Render_To_Opal (long Y, long Width, long Lines,
  27.             UBYTE *Red, UBYTE *Green, UBYTE *Blue, BOOL Chunky);
  28. void Opal_Render_Finished (void);
  29. void Close_Opal (void);
  30.  
  31.  
  32.  
  33. extern struct GfxBase *GfxBase;
  34. static struct OpalBase *OpalBase;
  35. static struct OpalScreen *OScrn,*VScrn;
  36. static long LastUpdateY,UpdateLines;
  37.  
  38.  
  39. /*   Open the Opalvision screen. Modes must be any combination of
  40.  * HIRES24,ILACE24,OVERSCAN24 as defined in Opallib.h.
  41.  *   The screen will be opened in chip ram if possible. If there
  42.  * is not enough chip ram, a virtual screen will be opened.
  43.  */
  44.  
  45.  
  46. BOOL Open_OpalScreen (ULONG Modes)
  47. {
  48.    long ImageSize;
  49.    long Width,Height;
  50.        if (OpalBase==NULL)
  51.         OpalBase = (struct OpalBase *)OpenLibrary ("opal.library",0);
  52.     if (OpalBase==NULL) return (FALSE);
  53.  
  54.         /* Calculate the amount of memory required for the screen */
  55.  
  56.     if (GfxBase->DisplayFlags & NTSC)
  57.         { if (Modes & OVERSCAN24)
  58.             { if (Modes & ILACE24)
  59.                 Height = 476;
  60.               else
  61.                 Height = 238;
  62.             }
  63.           else
  64.             { if (Modes & ILACE24)
  65.                 Height = 400;
  66.               else
  67.                 Height = 200;
  68.             }
  69.         }
  70.      else
  71.         { if (Modes & OVERSCAN24)
  72.             { if (Modes & ILACE24)
  73.                 Height = 576;
  74.               else
  75.                 Height = 286;
  76.             }
  77.           else
  78.             { if (Modes & ILACE24)
  79.                 Height = 512;
  80.               else
  81.                 Height = 256;
  82.             }
  83.         }
  84.  
  85.  
  86.     if (Modes & OVERSCAN24)
  87.         { if (Modes & HIRES24)
  88.             Width = 736L;
  89.           else
  90.             Width = 368L;
  91.         }
  92.     else
  93.         { if (Modes & HIRES24)
  94.             Width = 640L;
  95.           else
  96.             Width = 320L;
  97.         }
  98.  
  99.     if (Modes & PLANES8)
  100.         ImageSize = Width*Height;
  101.     else if (Modes & PLANES15)
  102.         ImageSize = Width*Height*2L;
  103.     else
  104.         ImageSize = Width*Height*3L;
  105.  
  106. #ifdef OPENVIRTUAL
  107.  
  108.     if (AvailMem (MEMF_CHIP)< (ImageSize +48000)) /* leave 48K safety JB */
  109.         { VScrn = CreateScreen24 (Modes,Width,Height);
  110.           if (VScrn==NULL) return (FALSE);
  111.           LastUpdateY = 0;
  112.           if (Modes & ILACE24)
  113.             UpdateLines =  12;
  114.           else
  115.             UpdateLines = 6;
  116.         }
  117.     else
  118. #endif
  119.         { OScrn = OpenScreen24 (Modes);
  120.           if (OScrn==NULL) return (FALSE);
  121. #ifdef AUTOSYNC
  122.           AutoSync24 (TRUE);
  123.           UpdateDelay24 (0);
  124. #else
  125.           UpdateDelay24 (10);
  126. #endif
  127.         }
  128.     return (TRUE);
  129. }
  130.  
  131. /* Render image RGB data to the OpalVision FrameBuffer.
  132.  *
  133.  * Inputs:
  134.  *    Y         = Staring Y-position (line) to place data.
  135.  *    Width         = Width of the RGB data.
  136.  *    Lines         = Number of scan lines to render.
  137.  *    Red,Green,Blue    = Pointers to Red, Green and Blue byte planes.
  138.  *    Chunky        = Set to TRUE if RGB data is in chunky (interleaved)
  139.  *              format.
  140.  */
  141.  
  142.  
  143. void Render_To_Opal (long Y, long Width, long Lines,
  144.             UBYTE *Red, UBYTE *Green, UBYTE *Blue, BOOL Chunky)
  145. {
  146.    UBYTE *RGBPlanes[3];
  147.    struct OpalScreen *WriteScreen;
  148.  
  149.     RGBPlanes[0] = Red;
  150.     RGBPlanes[1] = Green;
  151.     RGBPlanes[2] = Blue;
  152.     if (VScrn)
  153.         WriteScreen = VScrn;
  154.     else
  155.         WriteScreen = OScrn;
  156.     if (WriteScreen==NULL) return;
  157.     if (Chunky)
  158.         RGBtoOV (WriteScreen,RGBPlanes,0,Y,3*Width,Lines);
  159.     else
  160.         RGBtoOV (WriteScreen,RGBPlanes,0,Y,Width,Lines);
  161.     if (VScrn)
  162.         { if ((LastUpdateY/UpdateLines) != (Y/UpdateLines))
  163.             { OScrn = LowMemUpdate24 (VScrn,0);
  164.               LastUpdateY = Y;
  165.             }
  166.         }
  167.      else UpdateDelay24(20);   
  168. }
  169.  
  170. void Opal_Render_Finished (void)
  171. {
  172.     if (VScrn)
  173.         OScrn = LowMemUpdate24 (VScrn,0);
  174.     else StopUpdate24();    
  175. }
  176.     
  177.  
  178. void Close_Opal (void)
  179. {
  180.     if (OScrn)
  181.         CloseScreen24();
  182.     if (VScrn)
  183.         FreeScreen24 (VScrn);
  184.     if (OpalBase) CloseLibrary ((struct Library *)OpalBase);
  185.     OScrn = NULL;
  186.     VScrn = NULL;
  187.     OpalBase = NULL;
  188. }
  189.